import { _decorator, Color, Component, Label, Node, Sprite } from 'cc';
import { LevelModel } from './LevelModel';
const { ccclass, property } = _decorator;

@ccclass('LevelItem')
export class LevelItem extends Component {
  @property(Sprite)
  itemSpr: Sprite;
  @property(Label)
  itemLev: Label;
  @property(Node)
  itemCar: Node;
  isPass: boolean = false;
  curLev: number = -1;
  setLevelData(isPass: boolean, lev: number) {
    this.isPass = isPass;
    this.curLev = lev;
  }

  protected onEnable(): void {
    this.rendererUI();
  }

  rendererUI() {
    // this.itemSpr.color = new Color().fromHEX(this.isPass ? '#00ff00' : '#ff0000');
    this.itemSpr.grayscale = this.isPass ? false : true;
    this.itemLev.string = `${this.curLev}`;
  }

  selectLevel() {
    this.itemSpr.color = new Color().fromHEX('#ffff00');
  }

  passLevel() {
    this.isPass = true;
    this.rendererUI();
  }

  onClickLevel() {
    // if (this.isPass) return;
    // LevelModel.Ins().selectLevelItem(this);

    // if (DataMgr.gameParams.get(GameParams.energy_award) >= 3) {
    //   // this.closeSelf();
    //   (LevelModel.Ins().curPanel as PanelBase).closeSelf();
    //   GameModel.Ins().Show();
    //   // LevelModel.Ins().Show();
    // } else if (DataMgr.gameParams.get(GameParams.energy) <= 0) {
    //   EnergyModel.Ins().Show();
    // } else {
    //   EnergyModel.Ins().useEnergy(1);
    //   (LevelModel.Ins().curPanel as PanelBase).closeSelf();
    //   GameModel.Ins().Show();
    //   // LevelModel.Ins().Show();
    // }
  }
}
